package com.example.rs485demo;

import com.example.rs485demo.util.MyLister;
import com.example.rs485demo.util.PortInit;
import com.example.rs485demo.util.SerialPortUtil;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.scheduling.annotation.EnableScheduling;

import javax.annotation.PreDestroy;


@SpringBootApplication
@EnableScheduling
public class Rs485demoApplication {

    public static void main(String[] args) {
        SpringApplication.run(Rs485demoApplication.class, args);
    }

    @PreDestroy
    public void destory() {
        //关闭应用前 关闭端口
        SerialPortUtil serialPortUtil = SerialPortUtil.getSerialPortUtil();
        serialPortUtil.removeListener(PortInit.serialPort, new MyLister());
        serialPortUtil.closePort(PortInit.serialPort);

    }
}

